<template>
  <div class="m-view-home">
    <div id="bg" style="position: relative" v-if="showAdvert">
      <div id="text" style="position: absolute; top: 10px; left: 1185px">
        <el-button
          style="
            background: #909399;
            color: #ffffff;
            opacity: 0.6;
            border: none;
            font-weight: bold;
          "
          round
          @click="closePic"
          >{{ advertTime }}跳过</el-button
        >
      </div>
      <img src="@/assets/advertPic.png" @click="changeWay" />
    </div>
    <div class="m-top" v-if="!showAdvert">
      <div class="m-logo">
        <img src="@/assets/ls_logo.png" v-if="!inPlatform" />
        <span class="u-goback" @click="goBack" v-else
          >&lt;返回&nbsp;&nbsp;应用平台</span
        >
        <span>{{ systemTitle }}{{ appenvZH }}</span>
      </div>
      <div class="m-topRight">
        <div class="m-serviceSupport" @click="openServiceSupport" v-if="!isInnerUser && permitted">
          <i class="el-icon-service"></i>
          <span>服务支持</span>
        </div>
        <div class="m-help" @click="goHelpCenter">
          <i class="el-icon-help"></i>
          <span>帮助</span>
        </div>
        <div class="m-user">
          <el-dropdown trigger="hover" @command="handleCommand">
            <span class="el-dropdown-link">
              <img src="@/assets/user.png" />
              <span>{{ loginInfo }}</span>
              <i class="iconfont icon-xialasanjiao"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="1">修改密码</el-dropdown-item>
              <el-dropdown-item command="3">个人设置</el-dropdown-item>
              <el-dropdown-item command="2">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div class="m-function" v-if="userAgent == 'pc'">
          <span @click="winCtrl('min')">
            <i class="iconfont icon-minimize"></i>
          </span>
          <span @click="winCtrl('max')">
            <i class="iconfont icon-maxmize"></i>
          </span>
          <span @click="winCtrl('close')">
            <i class="iconfont icon-closeWin"></i>
          </span>
        </div>
      </div>
    </div>
    <div
      class="m-left"
      :style="telescopic ? 'width: 0' : ''"
      v-if="!showAdvert"
    >
      <ul>
        <li
          v-for="(item, index) in menuList"
          :key="index"
          @click="goMenu(item, true)"
          :class="{ active: item.name == titleName }"
        >
          <i :class="'iconfont icon-' + item.code"></i>
          <span>{{ item.name }}</span>
        </li>
      </ul>
    </div>
    <div
      class="m-right"
      :style="{
        bottom: userAgent == 'pc' ? '20px' : 0,
        left: telescopic ? 0 : '',
      }"
      v-if="!showAdvert"
      v-loading.fullscreen.lock="pageLoading"
    >
      <div class="m-telescopic">
        <button v-show="telescopic" @click="telescopicFalse">&gt;</button>
        <button v-show="!telescopic" @click="telescopicTure">&lt;</button>
      </div>
      <el-tabs
        v-model="editableTabsValue"
        @tab-remove="removeTab"
        @tab-add="addTab"
        type="card"
      >
        <el-tab-pane :label="titleName" name="1">
          <router-view :addTab="addTab"></router-view>
        </el-tab-pane>
        <el-tab-pane
          v-for="item in editableTabs"
          :label="item.title"
          :name="item.name"
          :key="item.name"
          closable
        >
          <component
            :is="item.content"
            :addTab="addTab"
            :isRefresh="isRefresh"
            :removeTab="removeTab"
            :systemInfo="systemInfo"
            :tabelData="planRowData"
            ref="componentContent"
          ></component>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="m-statusBar" v-if="userAgent == 'pc' && !showAdvert">
      <!-- <span>系统支持： 黄小姐：13549960089 左先生：18675715221</span> -->
      <span style="float: right">版本号：{{ version }}{{ appenv }}</span>
    </div>
    <!-- 修改密码弹窗开始 -->
    <el-dialog
      title="修改密码"
      :visible.sync="changePassword"
      v-dialogDrag
      :close-on-click-modal="false"
      :before-close="cancel"
    >
      <el-form
        label-width="100px"
        status-icon
        :rules="rules"
        ref="ruleForm"
        :model="ruleForm"
      >
        <el-form-item label="旧密码" prop="oldPass">
          <el-input
            placeholder="请输入旧密码"
            type="password"
            v-model="ruleForm.oldPass"
          ></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="pass">
          <el-input
            placeholder="请输入新密码"
            type="password"
            v-model="ruleForm.pass"
            auto-complete="off"
            @paste.native.capture="deletedPaste"
          ></el-input>
        </el-form-item>
        <el-form-item label="确认新密码" prop="checkPass">
          <el-input
            placeholder="再次确认新密码"
            type="password"
            v-model="ruleForm.checkPass"
            auto-complete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="confirmModify">确定</el-button>
      </span>
    </el-dialog>
    <!-- 修改密码弹窗结束 -->
    <!-- 个人设置弹窗开始 -->
    <el-dialog
      title="个人设置"
      :visible.sync="resetVisible"
      :close-on-click-modal="false"
      :before-close="handelClose"
      v-dialogDrag
      :show-close="showClose"
    >
      <el-form
        label-width="100px"
        :rules="rules"
        ref="userForm"
        class="demo-ruleForm"
        :model="userForm"
      >
        <el-form-item label="账号" prop="username">
          <el-input
            placeholder="请输入账号"
            v-model="userForm.username"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="employee_name">
          <el-input
            placeholder="请输入姓名"
            v-model="userForm.employee_name"
            auto-complete="off"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item
          label="邮箱"
          prop="email"
          :class="{ 'tip-form-item': emailTips }"
        >
          <el-input
            placeholder="请输入邮箱号码"
            type="email"
            v-model="userForm.email"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <span class="tips" v-show="emailTips"
          >设置邮箱可用于重置密码、接收系统邮件</span
        >
        <el-form-item
          label="手机号"
          prop="phone"
          :class="{ 'tip-form-item': phoneTips }"
          class="phone-form-item"
        >
          <el-input
            placeholder="请输入11位手机号"
            type="phone"
            v-model="userForm.phone"
            maxlength="11"
          ></el-input>
          <el-button
            type="primary"
            @click="getAuthCode"
            :disabled="failureTime < 60"
            :loading="sending"
          >
            {{
              failureTime < 60 ? `(${failureTime})S后重新获取` : "获取验证码"
            }}
          </el-button>
        </el-form-item>
        <span class="tips" v-show="phoneTips"
          >设置手机可用于接收系统短信提醒</span
        >
        <el-form-item label="验证码" prop="authCode">
          <el-input
            placeholder="请输入验证码"
            v-model="userForm.authCode"
            maxlength="4"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handelClose" v-if="showClose">取消</el-button>
        <el-button type="primary" @click="confirmSubmit" :disabled="btndis"
          >确定</el-button
        >
      </span>
    </el-dialog>
    <!-- 个人设置弹窗结束 -->
    <!-- 供应商资料设置 -->
    <div v-if="editDialogVisible">
      <supplierInfoPerfect
        :dialogVisible="editDialogVisible"
        @closeDialog="closeDialog"
      ></supplierInfoPerfect>
    </div>
    <!-- 送货单计划单导入弹窗-->
    <importDeliveryPlanDialog
      :importDialogVisible="importDialogVisible"
      v-if="importDialogVisible"
      @closeDialog="closeImportPlan"
      @saveImportData="saveImportData"
    ></importDeliveryPlanDialog>
    <!-- 服务支持弹框 -->
    <el-dialog
      title="服务支持"
      :visible.sync="serviceSupportDialogVisible"
      width="30%"
      :before-close="closeServiceSupport"
      v-dialogDrag
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="m-serviceSupport">
        <div class="m-serviceSupportHead" @click="handleDownCC">
          下载联塑CC客户端
        </div>
       

        <div class="m-serviceSupportBox">
          <div v-if="servicePersonnelBySupplierList.length != 0">
            <el-card
              class="m-boxCard"
              v-for="(item, index) in servicePersonnelBySupplierList"
              :key="index"
            >
              <div slot="header" class="clearfix">
                <span>{{ item.companyName }}</span>
              </div>
              <div
                v-for="(childItem, childIndex) in item.personnelList"
                :key="childIndex"
                class="m-serviceSupportContent"
              >
                <!-- <div>
                  <span class="m-serviceSupportName"
                    >{{ childItem.deptName }}&nbsp;&nbsp;:</span
                  ><span class="m-contactName">{{
                    childItem.contactName
                  }}</span>
                </div>
                <div>
                  <span class="m-serviceSupportCC">CC账号&nbsp;&nbsp;:</span
                  ><span class="m-ccAccount">{{ childItem.ccAccount }}</span>
                </div> -->
                <div>
                  <span class="m-serviceSupportName"
                    >{{ childItem.deptName }}&nbsp;&nbsp;:</span
                  ><span class="m-contactName">{{
                    childItem.contactName
                  }}</span>
                   <span class="m-serviceSupportCC">CC账号&nbsp;&nbsp;:</span
                  ><span class="m-ccAccount">{{ childItem.ccAccount }}</span>
                </div>
              
              </div>
            </el-card>
          </div>

          <div v-else class="m-noServiceData">没有相关供应商信息！！</div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<style lang="less"></style>

<script>
import { mapState, mapMutations, mapActions } from "vuex";
import sendMain from "lesso-common/event/ipcRenderer";
import components from "./components";
import _APIS from "@/api";
import utils from "@/public/utils";
import constant from "@/public/constant";
import waterfall from "async-es/waterfall";
import authorize from "@/public/authorize";
// import aes from "lesso-common/public/aes";
import aes from "@/public/aes";
import apienv from "@/api/env";
import websocketClient from "@lesso/common-websocket";
import { showAlert } from "lesso-common/public/utils";
import { webapp_urlprotocol_startup } from "lesso-common/webprint";


const valid = {
  validatePass1() {
    return function (rule, value, callback) {
      if (value === "") {
        callback(new Error("请输入旧密码"));
      } else {
        callback();
      }
    };
  },

  validatePass3() {
    return function (rule, value, callback) {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else {
        callback();
      }
    };
  },
};

const lxStr = function (str) {
  var arr = str.split("");
  var flag = true;
  for (var i = 1; i < arr.length - 1; i++) {
    var firstIndex = arr[i - 1].charCodeAt();
    var secondIndex = arr[i].charCodeAt();
    var thirdIndex = arr[i + 1].charCodeAt();
    // thirdIndex - secondIndex == 1;
    // secondIndex - firstIndex==1;
    if (thirdIndex - secondIndex == 1 && secondIndex - firstIndex == 1) {
      flag = false;
    }
  }
  return flag;
};
export default {
  name: "home",
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else if (value != "") {
        //jjc20181112
        // var reg = new RegExp("/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,20}$/");
        let reg = /^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,20}$/;
        let regCn = new RegExp("[\\u4E00-\\u9FFF]+", "g");
        let reg2 = /(\w)*(\w)\2{2}(\w)*/g;
        if (!reg.test(value)) {
          callback(
            new Error("密码必须8~20位长度，且为数字,字母及特殊符号组合！")
          );
        } else if (regCn.test(value)) {
          callback(new Error("密码不能包含汉字！"));
        } else if (value.indexOf(" ") > -1) {
          callback(
            new Error("密码不能输入空格，只能是数字,字母及特殊符号的组合！")
          );
        } else if (this.ruleForm.oldPass === value) {
          callback(new Error("新密码不能跟旧密码相同"));
        } else if (reg2.test(value)) {
          callback(new Error("相同的字符不能出现连续3位或3位以上"));
        } else if (!lxStr(value)) {
          callback(new Error("字母和数字不能出现连续3位或3位以上"));
        } else {
          callback();
        }
      }
    };
    var vaildPhone = (rule, value, callback) => {
      setTimeout(() => {
        if (value) {
          var reg = /^1(3[0-9]|4[0-9]|5[0,1,2,3,5,6,7,8,9]|6[0-9]|7[0-9]|8[0-9]|9[0-9])\d{8}$/;
          if (!reg.test(value)) {
            this.phoneTips = false;
            callback(new Error("请输入11位符合要求的手机号码"));
          } else {
            this.phoneTips = true;
            callback();
          }
        } else {
          this.phoneTips = false;
          callback(new Error("手机号码不能为空!"));
        }
      }, 100);
    };
    var checkMail = (rule, value, callback) => {
      setTimeout(() => {
        if (value) {
          var reg = new RegExp(
            "^([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)$"
          );
          if (!reg.test(value)) {
            this.emailTips = false;
            callback(new Error("请输入正确的邮箱地址"));
          } else this.emailTips = true;
          callback();
        } else {
          this.emailTips = true;
          callback();
        }
      }, 100);
    };
    var vaildAuthCode = (rule, value, callback) => {
      const { phone } = this.userInfo;
      if (this.userForm.phone && this.userForm.phone != phone) {
        if (!value) {
          callback(new Error("验证码不能为空"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      inPlatform: navigator.userAgent.indexOf("lslap") > -1, // 是否在应用平台中运行
      systemTitle: "联塑供应链管理系统",
      loading: true,
      menuList: [],
      editableTabsValue: "1",
      editableTabs: [],
      tabIndex: 1,
      titleName: "我的常用",
      version: "",
      appenv: `(${constant.appenv})`,
      appenvZH: "",
      loginInfo: "",
      isInnerUser: false,
      //新密码
      ruleForm: {
        oldPass: "",
        pass: "",
        checkPass: "",
      },
      rules: {
        oldPass: [
          {
            validator: valid.validatePass1(),
            trigger: "blur",
            required: true,
          },
        ],
        pass: [
          {
            validator: validatePass2,
            trigger: "blur",
            required: true,
          },
        ],
        checkPass: [
          {
            validator: valid.validatePass3(),
            trigger: "blur",
            required: true,
          },
        ],
        email: [
          {
            type: "email",
            validator: checkMail,
            trigger: "blur",
          },
        ],
        phone: [
          {
            required: true,
            validator: vaildPhone,
            trigger: "blur",
          },
        ],
        authCode: [
          {
            validator: vaildAuthCode,
            trigger: "blur",
          },
        ],
      },
      userForm: {
        username: "",
        employee_name: "",
        email: "",
        phone: "",
        authCode: "",
      }, //个人信息表单
      userInfo: "",
      resetVisible: false, //个人信息重置
      btndis: false,
      changePassword: false,
      isChangePassword: false,
      supplierInfo: {},
      keyWord: "",
      inputFilter: false,
      telescopic: false,
      wsClient: "",
      isRefresh: false,
      // 用户数据
      userData: {},
      emailTips: true,
      phoneTips: true,
      //控制广告图
      showAdvert: false,
      advertTime: 5,
      advertText: "",
      timer: null,

      // 供应商资料编辑
      editDialogVisible: false,
      // 当前环境
      userAgent: constant.userAgent,
      isClick: false,
      permitted: false,
      // 系统信息
      systemInfo: {
        systemCode: "srm",
        authUrl: apienv[constant.appenv].auth,
        systemId: this.$global.systemId,
      },
      // 页面加载
      pageLoading: false,
      // 是否显示送货计划单导入弹窗
      importDialogVisible: false,
      // 页签数据
      tabData: [],
      // 获取验证码
      failureTime: 60,
      sending: false,
      expireTimer: "",
      // 送货计划列表数据
      planRowData: [],
      showClose: true,
      serviceSupportDialogVisible: false, //服务支持弹框
      servicePersonnelBySupplierList: [], //服务相关人员
    };
  },
  computed: {
    ...mapState({
      supplyChainFinance: (state) => state.supplyChainFinance,
      app: (state) => state.app,
    }),
  },
  watch: {
    // 监控路由变化，设置进度标签和保存当前路由名称
    $route: {
      handler({ name }) {
        this.setCurrentRoute(name);
        for (let i in this.menuList) {
          if (this.menuList[i].code == name) {
            this.goMenu(this.menuList[i], false);
            this.checkAccountPhone();
            return;
          }
        }
      },
      immediate: true,
    },
  },
  methods: {
    ...mapMutations(["setCurrentRoute", "loginOut", "setUserData"]),
    ...mapActions(["changeSRMindexData"]),
    // 服务支持弹框
    openServiceSupport() {
      this.serviceSupportDialogVisible = true;
    },
    // 打开下载链接
    handleDownCC() {
      console.log("下载");
      window.open("http://cc.lesso.com/");
    },
    // 关闭服务支持弹框
    closeServiceSupport() {
      this.serviceSupportDialogVisible = false;
    },
    // 获取服务支持相关人员
    getServicePersonnelBySupplier() {
      _APIS
        .getServicePersonnelBySupplier()
        .then((response) => {
          console.log(response, "获取服务支持相关人员");
          let data = response.data;
          if (data.code == 1 && data.total != 0) {
            this.servicePersonnelBySupplierList = data.rows;
          } else {
            this.servicePersonnelBySupplierList = [];
          }
        })
        .catch((err) => {
          this.$alert(err.data.message, {
            showClose: false,
            confirmButton: "确定",
            customClass: "alertFailure",
          });
          this.serviceSupportDialogVisible = false;
        });
    },
    // 返回菜单窗口
    goBack() {
      sendMain("openMenuWin");
    },
    winCtrl(type) {
      switch (type) {
        case "min":
          sendMain("minWin");
          break;
        case "max":
          sendMain("maxWin");
          break;
        case "close":
          this.$confirm("是否确定退出程序", "消息提示", {
            distinguishCancelAndClose: true,
            showClose: false,
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            customClass: "confirmAsk",
          })
            .then(() => {
              sendMain("closeWin");
            })
            .catch((action) => {});
          break;
      }
    },
    // 阻止输入框粘贴事件
    deletedPaste(event) {
      event.preventDefault();
    },
    removeTab(targetName) {
      if (!targetName) {
        var targetName = this.editableTabsValue;
      }
      let tabs = this.editableTabs;
      let activeName = this.editableTabsValue;
      if (activeName === targetName) {
        tabs.forEach((tab, index) => {
          if (tab.name === targetName) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.name;
            }
          }
        });
      }
      if (tabs.length <= 1) {
        this.editableTabsValue = "1";
        this.editableTabs = tabs.filter((tab) => tab.name !== targetName);
        return;
      }
      this.editableTabsValue = activeName;
      this.editableTabs = tabs.filter((tab) => tab.name !== targetName);
    },
    addTab(data) {
      // 点击广告不记录点击次数
      if (!this.isClick) {
        this.addClickInfo(data);
      }
      this.isClick = false;
      let params = this.supplyChainFinance.custInf2;
      let that = this;
      let tabData = data;
      this.tabData = data;
      this.changeSRMindexData("");
      if (this.userData.user.userTypeId == "4") {
        if (this.$route.name == "accountManagement") {
          if (data.refresh) {
            this.isRefresh = !this.isRefresh;
          }
          if (this.supplierInfo != null && this.supplierInfo != "") {
            this.getAccountPermission(data, this.supplierInfo.supplierCode);
          }
          return;
        }
      }
      if (
        data.cName != "月有钱" &&
        data.cName != "天进宝" &&
        data.cName != "资料下载" &&
        data.cName != "供应商资料完善" &&
        data.cName != "担保人信息完善" &&
        data.cName != "金单宝" &&
        data.cName != "金货宝"
      ) {
        this.creationTab(data);
        return;
      }
      // this.creationTab(data)
      // return
      if (
        data.cName == "月有钱" ||
        data.cName == "天进宝" ||
        data.cName == "金单宝" ||
        data.cName == "金货宝"
      ) {
        if (data.cName == "金单宝" || data.cName == "金货宝") {
          that
            .getIsGuarantor()
            .then((name) => {
              constant.realController = name || "";
              if (name) {
                // that.creationTab(data)
                that.validCustIsfining(params, tabData);
              } else {
                that.$alert("担保人为空,请先维护担保人信息!", {
                  confirmButtonText: "确定",
                  customClass: "alertPrompt",
                  callback: () => {
                    that.creationTab({
                      cName: "担保人管理",
                      name: "guarantorManager",
                      completed: true,
                    });
                  },
                });
              }
              // that.validCustIsfining(params, tabData)
            })
            .catch((err) => {
              that.$alert(err, {
                confirmButtonText: "确定",
                customClass: "alertFailure",
              });
              return false;
            });
        } else {
          that
            .getIsGuarantor()
            .then((name) => {
              constant.realController = name || "";
              // that.creationTab(data)
              that.validCustIsfining(params, tabData);
            })
            .catch((err) => {});
        }
      }
      if (data.cName == "资料下载") {
        let appEnv = constant.appenv;
        let url =
          appEnv == "dev" || appEnv == "qas"
            ? "http://dev.lesso.com/edfx/srmpc/"
            : "http://app.lesso.com/edfx/srmpc/";
        if (this.userAgent == "web") {
          //   window.open(url, '_blank')
          utils.openNewWindow(url);
        } else {
          shell.openExternal(url);
        }
      }
      if (data.cName == "供应商资料完善") {
        this.editDialogVisible = true;
        return false;
      }
    },
    /**
     *@vuese
     * 验证该供应商是否有未完成的融资申请
     *
     *@arg 参数是Object，代表供应商信息
     */
    validCustIsfining(pramas, tabData) {
      this.$http
        .getOneOrSave(pramas)
        .then(({ data }) => {
          if (data.code == 200 && data.rows) {
            // '融资状态:0-未融资,1-在天进宝  2-在月有钱  3-逾期未还清  4-违约未还款  5-存在未放款申请' 6-在金货宝'
            this.isAllowFinancing = data.rows.finStatus <= 1 ? true : false;
            if (data.rows.finStatus != 0) {
              if (data.rows.finStatus == 5) {
                this.showAlertMes(
                  "贵司有笔融资申请还未放款，暂时无法进行新的融资申请，是否前往查看该笔融资申请？",
                  true
                );
                return false;
              } else if (data.rows.finStatus == 4) {
                this.showAlertMes(
                  "贵司有违约未还款的融资申请，无法进行新的融资申请，请联系联塑金融客服",
                  false
                );
                return false;
              } else if (data.rows.finStatus == 3) {
                this.showAlertMes(
                  "贵司有逾期未还清的融资申请，无法进行新的融资申请，请联系联塑金融客服",
                  false
                );
                return false;
              } else if (data.rows.finStatus == 2) {
                this.showAlertMes(
                  "贵司有笔 “月有钱” 申请正在进行，无法进行新的融资申请，请点击 “我的申请” 进行查看",
                  false
                );
                return false;
              } else if (
                data.rows.finStatus == 1 &&
                tabData.cName == "月有钱"
              ) {
                this.showAlertMes(
                  "贵司已有 “天进宝” 申请正在进行，无法进行新的 “月有钱” 申请，请点击 “我的申请” 进行查看",
                  false
                );
                return false;
              } else if (
                data.rows.finStatus == 6 &&
                tabData.cName == "月有钱"
              ) {
                this.showAlertMes(
                  "贵司已有 “金货宝” 申请正在进行，无法进行新的 “月有钱” 申请，请点击 “我的申请” 进行查看",
                  false
                );
                return false;
              } else if (
                data.rows.finStatus == 7 &&
                tabData.cName == "月有钱"
              ) {
                this.showAlertMes(
                  "贵司已有 “金单宝” 申请正在进行，无法进行新的 “月有钱” 申请，请点击 “我的申请” 进行查看",
                  false
                );
                return false;
              } else {
                this.creationTab(tabData);
              }
            }
            this.creationTab(tabData);
          } else {
            this.$alert("校验融资产品失败:" + data.info, {
              confirmButtonText: "确定",
              customClass: "alertFailure",
            });
            return false;
          }
        })
        .catch((errror) => {
          this.$alert("校验融资产品失败，请检查网络！", {
            confirmButtonText: "确定",
            customClass: "alertFailure",
          });
          return false;
        });
    },
    // 判断该供应商是否已维护担保人信息
    getIsGuarantor() {
      let pramas = {
        supplierCode: this.$global.supplierData.supplierCode,
      };
      return new Promise((resolve, reject) => {
        this.$http
          .getIsGuarantor(pramas)
          .then(({ data }) => {
            if (data.code == 1) {
              resolve(data.rows);
            } else {
              reject(data.info);
            }
          })
          .catch((err) => {});
      });
    },
    //记录点击次数信息接口
    addClickInfo(data) {
      var obj = {
        functionCode: data.name,
        functionName: data.cName,
        creatorId: constant.userId,
        creator: constant.userName,
      };
      _APIS
        .addClickHistory(obj)
        .then(function (response) {
          var data = response.data;
          if (data.code == "1") {
            console.log("记录点击信息成功！");
          }
        })
        .catch((err) => {});
    },

    creationTab(data) {
      if (this.editableTabs.length > 0) {
        var flag = false;
        var item;
        for (var i = 0; i < this.editableTabs.length; i++) {
          if (data.cName == this.editableTabs[i].title) {
            flag = true;
            item = this.editableTabs[i];
            break;
          }
        }
        if (flag) {
          this.editableTabsValue = item.name;
        } else {
          let newTabName = ++this.tabIndex + "";
          this.editableTabs.push({
            title: data.cName,
            name: newTabName,
            content: data.name,
          });
          this.editableTabsValue = newTabName;
        }
      } else {
        let newTabName = ++this.tabIndex + "";
        this.editableTabs.push({
          title: data.cName,
          name: newTabName,
          content: data.name,
        });
        this.editableTabsValue = newTabName;
      }
    },
    // 验证是否有对账权限
    getAccountPermission(tabData, supplierCode) {
      this.$http
        .getAccountPermission({ supplierCode: supplierCode })
        .then(({ data }) => {
          if (data.code == 1) {
            this.creationTab(tabData);
          } else {
            this.$alert(data.info, {
              showClose: false,
              confirmButtonText: "确定",
              customClass: "alertPrompt",
            });
          }
        })
        .catch((err) => {
          this.$alert(err.data.message, {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
        });
    },
    // 切换菜单
    goMenu(menuData, flag) {
      
      this.editableTabsValue = "1";
      this.$router.push("/home/" + menuData.code); //data.name
      this.titleName = menuData.name;
      utils.saveMenuId("menuId", menuData.id);
      if (menuData.name == "融资管理" && flag) {
        //点击“融资管理”做是否存在未放款单据的校验
        let urlName = menuData.name;
        let params = this.supplyChainFinance.custInf2;
        let that = this;
        that.$http
          .getOneOrSave(params)
          .then(({ data }) => {
            if (data.code == 200 && data.rows) {
              if (data.rows.finStatus == 5 && urlName == "融资管理") {
                that.showAlertMes(
                  "贵司有笔融资申请还未放款，是否前往查看该笔融资申请？",
                  true
                );
              }
            } else {
              that.$alert(data.info, {
                confirmButtonText: "确定",
                customClass: "alertFailure",
              });
            }
          })
          .catch((errror) => {
            console.log("111", errror);
            that.$alert("网络错误，请检查网络！", {
              confirmButtonText: "确定",
              customClass: "alertFailure",
            });
            return false;
          });
      }
    },
    //获取SRM融资申请的数据
    getUnLoanApplyInfoMap() {
      let params = {
        custId: this.supplyChainFinance.custInf2.id,
      };
      let that = this;
      this.$http
        .getUnLoanApplyInfoMap(params)
        .then(({ data }) => {
          if (data.code == 200 && data.rows) {
            that.rowData = data.rows;
            that.goApplyList();
          } else {
            that.$alert(data.info, {
              confirmButtonText: "确定",
              customClass: "alertFailure",
            });
          }
        })
        .catch((errror) => {
          that.$alert("网络xxxx错误，请检查网络！", {
            confirmButtonText: "确定",
            customClass: "alertFailure",
          });
          return false;
        });
    },
    getMenu() {
      authorize
        .getNavAuth()
        .then((res) => {
          console.log("left--菜单", res);
          this.menuList = res;
          // this.goMenu(this.activeMenu[0]);
        })
        .catch((err) => {
          this.$alert("无系统权限，请联系管理员", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertFailure",
          });
        });
      // var obj = {
      // 	resourceType: 0,
      // 	type: 1
      // };
      // var that = this;
      // this.pageLoading = true
      // _APIS.getMenu(obj).then(function (response) {
      // 	var data = response;
      // 	that.pageLoading = false
      // 	if (data.data.code == "1") {
      // 		if (data.data.rows.rootNodes.length > 0) {
      // 			that.menuList = data.data.rows.rootNodes[0].children;
      // 			utils.saveSession('auth', that.menuList);
      // 		} else {
      // 			that.$alert('无系统权限,请联系管理员!', {
      // 				showClose: false,
      // 				confirmButton: "确定",
      // 				customClass: "alertFailure"
      // 			});
      // 		}
      // 	} else {
      // 		that.pageLoading = false
      // 		that.$alert(data.data.msg, {
      // 			showClose: false,
      // 			confirmButton: "确定",
      // 			customClass: "alertFailure"
      // 		});
      // 	}
      // }).catch((err) => {
      // 	that.pageLoading = false
      // 	// that.$alert(err.data.message, {
      // 	//   showClose: false,
      // 	//   confirmButton: "确定",
      // 	//   customClass: "alertFailure"
      // 	// });
      // })
    },
    getUserId() {
      this.userInfo = constant.user;
      const { userName, employeeName, email, phone } = this.userInfo;
      this.userForm = {
        username: userName,
        employee_name: employeeName,
        email,
        phone,
      };
      if (this.userData.user.userTypeId == 4) {
        Promise.all([this.loadSupplierInfo(), this.accountIstransport()])
          .then((result) => {
            let rows = result[0];
            let transport = result[1];
            if (rows.length > 0) {
              this.supplierInfo = rows[0];
              constant.supplierId = this.supplierInfo.id;
              constant.supplierData = this.supplierInfo;
            } else {
              constant.supplierId = "";
              constant.supplierData = null;
            }
            if (transport) {
              constant.isTransport = true;
              constant.transport = transport;
            } else {
              constant.isTransport = false;
              constant.transport = null;
            }
            this.getMenu();
          })
          .catch((err) => {
            this.$alert(err, {
              showClose: false,
              confirmButtonText: "确定",
              customClass: "alertFailure",
            });
          });
      } else {
        constant.supplierId = "";
        constant.supplierData = null;
      }
    },
    // 供应商账号类型时获取供应商信息
    loadSupplierInfo() {
      return new Promise((resolve, reject) => {
        let obj = {
          mainAccount: this.userData.user.userName,
        };
        _APIS
          .getSupplierDetailByAccount(obj)
          .then((response) => {
            let data = response.data;
            if (data.code == "1") {
              resolve(data.rows);
            } else {
              reject(data.info);
            }
          })
          .catch((err) => {
            reject("获取供应商信息失败！");
          });
      });
    },
    // 判断当前账号是否是运输方
    accountIstransport() {
      return new Promise((resolve, reject) => {
        _APIS
          .validIstransport({ accountCode: this.userData.user.userName })
          .then(({ data }) => {
            if (data.code == 1) {
              resolve(data.rows);
            } else {
              reject(data.info);
            }
          });
      }).catch((err) => {
        reject(err.data.message);
      });
    },
    handleCommand(command) {
      let that = this;
      switch (command) {
        case "1":
          this.validateAccount()
            .then((info) => {
              constant.isAccount = info;
              if (info == "3") {
                //   主账号及内部人员账号权限系统修改密码
                this.changePassword = true;
              } else {
                // 非子账号跳转idm修改密码
                this.getIdmModifyUrl();
              }
            })
            .catch((err) => {
              this.$alert(err, {
                showClose: false,
                confirmButtonText: "确定",
                customClass: "alertFailure",
              });
            });
          break;
        case "2":
          this.$confirm("是否确定退出登录？", "消息提示", {
            distinguishCancelAndClose: true,
            showClose: false,
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            customClass: "confirmAsk",
          })
            .then(() => {
              _APIS
                .userLogout({
                  uid: this.userData.user.id,
                  systemId: constant.systemId,
                })
                .then(function (res) {
                  that.loginOut();
                  constant.token = "";
                  if (that.userAgent == "web") {
                    that.$router.push({
                      name: "login",
                    });
                  } else {
                    sendMain("openLoginWin");
                  }
                })
                .catch(function (err) {
                  that.loginOut();
                  constant.token = "";
                  if (that.userAgent == "web") {
                    that.$router.push({
                      name: "login",
                    });
                  } else {
                    sendMain("openLoginWin");
                  }
                });
            })
            .catch((action) => {});
          break;
        case "3":
          this.resetVisible = true;
          this.emailTips = true;
          this.phoneTips = true;
          if (this.expireTimer) clearInterval(this.expireTimer);
          this.failureTime = 60;
          break;
      }
    },
    // 获取idm接口修改地址
    getIdmModifyUrl() {
      _APIS.modifyPassword().then(({ data }) => {
        let userName = "";
        let url = "";
        if (this.userAgent == "web") {
          userName = utils.getSession("currentAct");
          url = `${data}?userid=${userName}`;
          //   window.open(url, '_blank')
          //   let newWeb = window.open('_blank')
          //   newWeb.location.href = url;
          utils.openNewWindow(url);
        } else {
          userName = remote.getGlobal("balance");
          url = `${data}?userid=${userName}`;
          shell.openExternal(url);
        }
      });
    },
    // 子账号修改密码
    confirmModify() {
      var that = this;
      if (
        this.ruleForm.checkPass != "" &&
        this.ruleForm.pass != this.ruleForm.checkPass
      ) {
        that.$alert("两次输入密码不一致!", {
          showClose: false,
          confirmButtonText: "确定",
          customClass: "alertFailure",
        });
        return;
      }
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          waterfall(
            [
              function getTokeapin(callback) {
                _APIS.getToken({ tokenkey: "get" }).then(
                  function success(res) {
                    var data = res.data;
                    if (data.meta.code === 200) {
                      callback(null, data);
                    } else {
                      callback(res, 1);
                    }
                  },
                  function error(err) {
                    callback(err, 0);
                  }
                );
              },
              function editPassword(tokenData, callback) {
                _APIS
                  .validatePassword({
                    password: aes.encrypt(
                      that.ruleForm.oldPass,
                      tokenData.data.tokenKey
                    ),
                    userkey: tokenData.data.userKey,
                    tokenKey: tokenData.data.tokenKey,
                  })
                  .then(
                    function success(res) {
                      if (res.data.code == 1) {
                        var obj = {
                          //   tokenkey: tokenData.data.tokenKey,
                          decryptKey: tokenData.data.tokenKey,
                          //   userkey: tokenData.data.userKey,
                          newpwd: aes.encrypt(
                            that.ruleForm.pass,
                            tokenData.data.tokenKey
                          ),
                          //   userName: that.userData.user.userName,
                          //                                                  id: constant.userId
                          accountId: that.userData.user.id,
                        };
                        _APIS.editPasswordIdm(obj).then(
                          function success(res) {
                            if (res.data.code == 1) {
                              that.$alert("操作成功,请重新登录", {
                                showClose: false,
                                confirmButtonText: "确定",
                                customClass: "alertSuccess",
                                callback: function () {
                                  that.loginOut();
                                  if (that.userAgent == "web") {
                                    that.$router.push({
                                      name: "login",
                                    });
                                  } else {
                                    sendMain("openLoginWin");
                                  }
                                },
                              });
                              // callback(null,tokenData)
                            } else {
                              callback(res, 2);
                            }
                          },
                          function error(err) {
                            callback(err, 3);
                          }
                        );
                      } else {
                        callback(res, 4);
                      }
                    },
                    function error(err) {
                      callback(err, 5);
                    }
                  );
              },
              function editPassword1(token, callback) {
                let pramas = {
                  accountId: that.userData.user.id,
                  newpwd: aes.encryptMd5(that.ruleForm.pass),
                };
                _APIS.editPasswordIdm(pramas).then(
                  function success(res) {
                    if (res.data.code == 1) {
                      //   that.$alert("操作成功,请重新登录", {
                      //     showClose: false,
                      //     confirmButtonText: "确定",
                      //     customClass: "alertSuccess",
                      //     callback: function () {
                      //       that.loginOut()
                      //       if (that.userAgent == 'web') {
                      //         that.$router.push({
                      //           name: 'login'
                      //         })
                      //       } else {
                      //         sendMain("openLoginWin");
                      //       }
                      //     }
                      //   });
                      console.log("cc密码修改成功");
                    } else {
                      //   callback(res, 2);
                    }
                  },
                  function error(err) {
                    // callback(err, 3);
                  }
                );
              },
            ],
            function (err, result) {
              let errMsg;
              switch (result) {
                case 0:
                case 1:
                  errMsg = err.data.meta.msg;
                  break;
                case 2:
                  errMsg = err.data.info;
                  break;
                case 3:
                  errMsg = "修改密码失败，请检查网络";
                  break;
                case 4:
                  errMsg = "旧密码验证错误，请重新输入";
                  break;
                case 5:
                  errMsg = "旧密码验证失败，请检查网络";
                  break;
                case 6:
                  errMsg = err.data.message;
                  break;
              }
              that.$alert(errMsg, {
                showClose: false,
                confirmButtonText: "确定",
                customClass: "alertFailure",
              });
            }
          );
          // let obj = {
          //     oldPassword:aes.encrypt(
          //               this.ruleForm.oldPass
          //             ),
          //     newPassword:'',
          //     userName:''
          // }
          // _APIS.editPasswordIdm(obj).then()
        }
      });
    },
    // 确认提交个人设置信息
    confirmSubmit() {
      this.$refs["userForm"].validate((vaild) => {
        if (vaild) {
          const { username, email, phone, authCode } = this.userForm;
          let pramas = {
            username,
            email,
            phone,
          };
          this.btndis = true;
          this.updatePersonal(pramas)
            .then((_) => {
              let userData = utils.getSession("userData");
              userData.user.phone = phone;
              userData.user.email = email;
              utils.saveSession("userData", userData);
              this.saveConstant();
              this.$alert("个人信息设置成功!", {
                showClose: false,
                confirmButtonText: "确定",
              });
              this.handelClose();
              this.btndis = false;
            })
            .catch((err) => {
              this.btndis = false;
              this.$alert(err, {
                showClose: false,
                confirmButtonText: "确定",
                customClass: "alertFailure",
              });
            });
          if (phone && phone != this.userInfo.phone) {
            _APIS
              .validaAuthCode({ verifyNum: authCode, phone })
              .then(({ data }) => {
                if (data.code == 1) {
                  this.updatePersonal(pramas)
                    .then((_) => {
                      let userData = utils.getSession("userData");
                      userData.user.phone = phone;
                      userData.user.email = email;
                      utils.saveSession("userData", userData);
                      this.saveConstant();
                      this.$alert("个人信息设置成功!", {
                        showClose: false,
                        confirmButtonText: "确定",
                      });
                      this.handelClose();
                      this.btndis = false;
                    })
                    .catch((err) => {
                      this.$alert(err, {
                        showClose: false,
                        confirmButtonText: "确定",
                        customClass: "alertFailure",
                      });
                      this.btndis = false;
                    });
                } else {
                  this.$alert(data.info, {
                    showClose: false,
                    confirmButtonText: "确定",
                    customClass: "alertFailure",
                  });
                  this.btndis = false;
                }
              })
              .catch((err) => {
                this.btndis = false;
                this.$alert(err.data.message, {
                  showClose: false,
                  confirmButtonText: "确定",
                  customClass: "alertFailure",
                });
              });
          } else {
            this.updatePersonal(pramas)
              .then((_) => {
                let userData = utils.getSession("userData");
                userData.user.phone = phone;
                userData.user.email = email;
                utils.saveSession("userData", userData);
                this.saveConstant();
                this.$alert("个人信息设置成功!", {
                  showClose: false,
                  confirmButtonText: "确定",
                });
                this.handelClose();
                this.btndis = false;
              })
              .catch((err) => {
                this.btndis = false;
                this.$alert(err, {
                  showClose: false,
                  confirmButtonText: "确定",
                  customClass: "alertFailure",
                });
              });
          }
        }
      });
    },
    // 修改个人信息
    updatePersonal(obj) {
      return new Promise((resolve, reject) => {
        _APIS
          .personalReset(obj)
          .then((res) => {
            let data = res.data;
            if (data.code == 1) {
              resolve();
            } else {
              reject(data.info);
            }
          })
          .catch((err) => {
            console.log("异常", err);
            reject(err.data.message);
          });
      });
    },
    // 关闭个人设置弹窗
    handelClose() {
      this.resetVisible = false;
      this.$refs.userForm.resetFields();
      const { email, phone } = constant.user;
      this.userForm.email = email;
      this.userForm.phone = phone;
    },
    //取消按钮关闭模态框
    cancel() {
      this.changePassword = false;
      this.ruleForm.oldPass = "";
      this.ruleForm.pass = "";
      this.ruleForm.checkPass = "";
      this.$refs.ruleForm.resetFields();
    },
    // 显示当前程序环境
    getAppenvZH() {
      if (constant.appenv == "dev") {
        this.appenvZH = "(开发环境)";
      } else if (constant.appenv == "qas") {
        this.appenvZH = "(测试环境)";
      } else if (constant.appenv == "app") {
        this.appenvZH = "(正式环境)";
      }
      return this.appenvZH;
      //console.log(this.appenvZH)
    },
    // 存储全局变量
    saveConstant() {
      let localData = utils.getSession("userData");
      constant.userId = localData.user.id;
      constant.userName = localData.user.employeeName;
      constant.employeeName = localData.user.employeeName;
      constant.sapNum = localData.user.sapNum;
      constant.token = localData.token;
      constant.account = localData.user.userName;
      constant.accountType = localData.user.userTypeId;
      constant.phone = localData.user.phone;
      constant.bukrs = localData.user.bukrs;
      constant.butxt = localData.user.butxt;
      constant.user = localData.user;
      constant.system = localData.system;
      this.isInnerUser = localData.user.userTypeId == 1;
      this.$systemInfo.userId = localData.user.id;
    },
    telescopicTure() {
      this.telescopic = true;
    },
    telescopicFalse() {
      this.telescopic = false;
    },
    //获取供应商信息
    getCustInf() {
      this.$store.dispatch("queryMstSupplierInfo", {
        mainAccount: this.userData.user.userName,
      });
    },
    // 关闭资料完善编辑框
    closeDialog() {
      this.editDialogVisible = false;
    },
    // 关闭送货计划导入弹窗
    closeImportPlan() {
      this.importDialogVisible = false;
    },
    showAlertMes(message, isScan) {
      this.$confirm(message, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          if (isScan) {
            this.getUnLoanApplyInfoMap();
          }
        })
        .catch(() => {});
    },
    //点击广告图跳入融资管理界面
    changeWay() {
      this.isClick = true;
      this.addTab({
        cName: "产品介绍",
        name: "productionIntroduce",
        completed: false,
      });
      if (this.userData.user.isDefaultPwd == true) {
        this.changePassword = true;
      }
      this.showAdvert = false;
      clearInterval(this.timer);
    },
    // 关闭图片
    closePic() {
      clearInterval(this.timer);
      this.showAdvert = false;
      if (this.isChangePassword == true) {
        this.changePassword = true;
      }
    },
    // 确认导入送货计划跳转到创建计划单页
    saveImportData(planRowData) {
      this.planRowData = planRowData;
      this.creationTab(this.tabData);
      this.importDialogVisible = false;
    },
    goApplyList() {
      let data = {
        cName: "我的申请",
        completed: false,
        name: "applyList",
      };
      this.creationTab(data);
      let rowData = this.rowData;
      this.changeSRMindexData(rowData);
    },
    // 验证账号是否是主账号
    validateAccount() {
      return new Promise((resolve, reject) => {
        _APIS
          .validateAccount({ userName: this.userData.user.userName })
          .then(({ data }) => {
            if (data.code == 1) {
              resolve(data.info);
            } else {
              reject(data.info);
            }
          })
          .catch((err) => {
            reject(err.data.message);
          });
      });
    },
    // 查看帮助
    goHelpCenter() {
      let menuItem = {
        cName: "帮助中心",
        name: "helpCenter",
        completed: true,
      };
      this.addTab(menuItem);
    },
    // 获取验证码
    getAuthCode() {
      if (this.expireTimer) {
        clearInterval(this.expireTimer);
      }
      this.sending = true;
      this.$http
        .getAuthCode({ phone: this.userForm.phone })
        .then(({ data }) => {
          this.sending = false;
          if (data.code == 1) {
            this.failureTime = 59;
            this.expireTimer = setInterval(() => {
              if (this.failureTime > 0 && this.failureTime < 61) {
                this.failureTime--;
              } else {
                clearInterval(this.expireTimer);
                this.failureTime = 60;
              }
            }, 1000);
          } else {
            this.$alert(data.info, {
              showClose: false,
              confirmButtonText: "确定",
              customClass: "alertFailure",
            });
          }
        })
        .catch((err) => {
          this.sending = false;
          this.$alert(err.data.message, {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertFailure",
          });
        });
    },
    // 供应商主账号验证为维护手机号提示并强制要求修改手机号
    checkAccountPhone() {
      const { isIdm, phone, userTypeId } = constant.user;
      if (isIdm == 1 && !phone && userTypeId == 4) {
        this.$alert(
          "系统检测到您的手机号为空<br/>请点击确定维护您的手机号码,方可继续使用!",
          "提示",
          {
            confirmButtonText: "确定",
            dangerouslyUseHTMLString: true,
            type: "warning",
            callback: (_) => {
              this.resetVisible = true;
              this.showClose = false;
              this.emailTips = true;
              this.phoneTips = true;
              if (this.expireTimer) clearInterval(this.expireTimer);
              this.failureTime = 60;
            },
          }
        );
      }
    },
    getEnabled(){
         _APIS.getEnabled().then(({data}) => {
           if(data.data != '0') {
             this.permitted = true;
           }
          })
    },
  },
  components: components,
  created() {
    let that = this;
    if (constant.userAgent == "pc") {
      let userData = remote.getGlobal("userData");
      this.setUserData(userData);
    } else {
      var isSafari = navigator.vendor && navigator.vendor.indexOf("Apple") > -1;
      if (!isSafari) webapp_urlprotocol_startup();
    }
    this.saveConstant();
    this.userData = utils.getSession("userData");
    this.version = constant.appVersion;
    if (this.userData.user.userTypeId == 4) {
      this.getUserId();
      this.checkAccountPhone();
    } else {
      this.getUserId();
      this.getMenu();
    }
    this.getCustInf();
    this.getEnabled();
    this.wsClient = new websocketClient({
      systemEnv: constant.appenv,
      userId: constant.userId,
      systemCode: constant.authCode.code,
      loginTimestamp: this.userData.timestamp,
      fanoutCallback: (msg) => {
        let res = JSON.parse(msg.body);
        console.log("ws res:", msg);
        this.$notify({
          title: `系统通知`,
          message: res.message,
          type: "warning",
          duration: 0,
          position: "bottom-right",
        });
      },
      topicCallback: (msg) => {
        let res = JSON.parse(msg.body);
        console.log("ws res:", msg);
        this.$notify({
          title: `来自${res.userName}的通知`,
          message: res.message,
          type: "warning",
          duration: 0,
          position: "bottom-right",
        });
      },
      logoutCallback: (forceOffline) => {
        if (constant.appenv != "dev") {
          if (forceOffline) {
            showAlert({
              msg: `帐号已被强制下线`,
              type: 2,
            }).then(() => {
              _APIS
                .userLogout({
                  uid: constant.userId,
                  systemId: constant.systemId,
                })
                .then(function (res) {
                  that.$store.commit("loginOut");
                  if (that.userAgent == "web") {
                    that.$router.push({
                      name: "login",
                    });
                  } else {
                    sendMain("openLoginWin");
                  }
                })
                .catch(function (err) {
                  that.$store.commit("loginOut");
                  if (that.userAgent == "web") {
                    that.$router.push({
                      name: "login",
                    });
                  } else {
                    sendMain("openLoginWin");
                  }
                });
            });
          } else {
            showAlert({
              msg: `帐号已在别处登录`,
              type: 2,
            }).then(() => {
              that.$store.commit("loginOut");
              if (that.userAgent == "web") {
                that.$router.push({
                  name: "login",
                });
              } else {
                sendMain("openLoginWin");
              }
            });
          }
        }
      },
    });
    this.wsClient.connect();
    this.getServicePersonnelBySupplier(); //服务人员信息
  },
  beforeMount() {
    this.getAppenvZH();
  },
  mounted() {
    if (this.userAgent == "pc") {
      this.showAdvert = true;
      clearInterval(this.timer);
      this.timer = setInterval(() => {
        if (this.advertTime > 0) {
          this.advertTime = this.advertTime - 1;
        } else {
          clearInterval(this.timer);
          this.showAdvert = false;
          if (this.userData.user.isDefaultPwd == true) {
            this.changePassword = true;
          }
        }
      }, 1000);
    } else {
      this.showAdvert = false;
      if (this.userData.user.isDefaultPwd == true) this.changePassword = true;
    }
    this.loginInfo =
      this.userData.user.loginName + "(" + this.userData.user.userName + ")";
    let _this = this;
    this.$tap.$on("removeTabFn", function () {
      _this.removeTab();
    });
    this.$tap.$on("addTabFn", function (tab) {
      _this.addTab(tab);
    });
    if (this.$sentry) {
      this.$sentry.setUser({
        id: this.userData.user.id,
        name: this.userData.user.employeeName,
      });
    }
  },
  destroyed() {
    this.wsClient.disconnent();
  },
};
</script>
<style lang="less">
/* 设置滚动条的样式 */
.m-serviceSupportBox::-webkit-scrollbar {
  display: none;
}
</style>
